Skip to content

fix(glm4_moe): accept Transformers 5.22 router tuple - #72

Merged
Qubitium merged 1 commit into
mainfrom
fix/glm4-moe-router-tuple
Nov 14, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/glm4-moe-router-tuple

Conversation

@Qubitium

Copy link
Copy Markdown
Contributor

Summary

Defuser's GLM-4.x replacement MoE blocks crash on Transformers 5.22 because the router now returns (router_logits, topk_weights, topk_indices) and LinearGlm4MoeMoE / LinearGlm4MoeLiteMoE passed that tuple straight into route_tokens_to_experts(), which calls .sigmoid():

AttributeError: 'tuple' object has no attribute 'sigmoid'

This is the upstream fix requested by the reviewer note in ModelCloud/GPTQModel#4055 (issue ModelCloud/GPTQModel#4040, section F).

Fix

  • route_tokens_to_experts() now accepts either the raw logits tensor or the Transformers 5.22 router tuple and unwraps router_output[0].
  • forward() passes the router output through unchanged; the block no longer assumes a tensor.
  • Only the raw logits are used. The router's precomputed top-k weights/indices are intentionally discarded because Defuser re-derives grouped top-k selection itself, so the routing math stays byte-identical across Transformers versions.
  • Bump version 0.0.30 -> 0.0.31 so dependents can gate on the release.

Tests

  • test_glm4_route_tokens_accepts_tuple_and_tensor_equivalently (both glm4_moe and glm4_moe_lite): tuple and tensor inputs produce bit-identical indices and weights.
  • test_defused_glm4_model_forward_accepts_router_tuple (both families): full defused model forward succeeds and produces finite logits.
  • Existing test_glm4_moe_defused_forward_matches_fused_math and test_glm4_moe_lite_defused_forward_matches_fused_math now pass; they previously failed with the tuple error.
$ python -m pytest tests/test_convert_model.py -k glm4 -q
11 passed

Full suite: 151 passed / 21 failed, identical to main's 145 passed / 23 failed except for the two GLM-4 defused-forward tests this fixes. The remaining failures are pre-existing on main under the local Transformers build (unrelated registry cases).

Release dependency

GPTQModel will raise its defuser floor to >=0.0.31 in a paired PR once this release is published. The current GPTQModel defuser_compat shim is removed by that PR.

Transformers 5.22 routers return (router_logits, topk_weights,
topk_indices). LinearGlm4MoeMoE and LinearGlm4MoeLiteMoE passed that
tuple straight into route_tokens_to_experts(), which calls .sigmoid(),
so the first MoE layer raised:

    AttributeError: 'tuple' object has no attribute 'sigmoid'

Unwrap the tuple to the raw logits before Defuser's grouped top-k
selection. The router's precomputed top-k is intentionally discarded so
the routing math stays byte-identical across Transformers versions.

Bump Defuser to 0.0.31 for the GPTQModel version gate.
@Qubitium
Qubitium merged commit c100898 into main Nov 14, 2026
28 checks passed
@Qubitium
Qubitium deleted the fix/glm4-moe-router-tuple branch November 14, 2026 19:33
sLaffey pushed a commit to sLaffey/GPTQModel that referenced this pull request Nov 18, 2026
Defuser 0.0.31 fixes the GLM-4.5/4.6/4.7 and GLM-4.7-Flash replacement
MoE blocks, which passed the Transformers 5.22 router tuple
(router_logits, topk_weights, topk_indices) into
route_tokens_to_experts() and crashed on .sigmoid().

Raise the floor to defuser>=0.0.31 and remove the local
gptqmodel/utils/defuser_compat.py shim now that the fix is upstream.
Update the Tenstorrent manifest pin, version-gate tests, and the
Transformers 5.22 compatibility docs.

Depends on ModelCloud/Defuser#72 and the 0.0.31 release.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant